package com.robot.api.dao;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;

import com.robot.api.common.util.BizLogger;


public abstract class AbstractBaseDao {
	public BizLogger logger = BizLogger.getLogger(this.getClass());
	
	@SuppressWarnings("unchecked")
	public RowMapper mappingResult(Class<?> resultBean) {
		return new BeanPropertyRowMapper(resultBean);
	}

	public BeanPropertySqlParameterSource mappingParameter(Object parameter) {
		return new BeanPropertySqlParameterSource(parameter);
	}

	public BeanPropertySqlParameterSource[] mappingParamList(List<? extends Object> paramList) {
		BeanPropertySqlParameterSource[] result = new BeanPropertySqlParameterSource[paramList.size()];
		int i = 0;
		for (Object parameter : paramList) {
			result[i] = new BeanPropertySqlParameterSource(parameter);
			i++;
		}
		return result;
	}
	
	public MapSqlParameterSource mappingParameter(Map<String, Object> paramMap){
		MapSqlParameterSource inParam = new MapSqlParameterSource(paramMap);
		return inParam;
	}
	
	
}
